package site.lanmushan.quiz.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import site.lanmushan.common.dto.Message;
import org.springframework.web.bind.annotation.*;
import site.lanmushan.common.dto.QueryInfo;
import site.lanmushan.common.query.annotations.RequestQueryInfo;
import site.lanmushan.common.query.controller.BaseController;
import site.lanmushan.quiz.api.ao.QuizTbQuestionAo;
import site.lanmushan.quiz.api.entity.QuizTbQuestion;
import site.lanmushan.quiz.api.service.IQuizTbQuestionService;

import java.util.List;
import javax.validation.Valid;

import site.lanmushan.common.bizlog.annotations.BizLog;
import site.lanmushan.common.bizlog.consts.BizLogType;
import site.lanmushan.quiz.api.vo.QuestionAnswersVo;
import site.lanmushan.quiz.api.vo.QuizTbQuestionListVo;

/**
 * @author $author
 * 测验问题
 */
@RestController
@RequestMapping(name = "测验问题", value = "/QuizTbQuestion")
@Slf4j
public class QuizTbQuestionController extends BaseController {
    @Autowired
    IQuizTbQuestionService iQuizTbQuestionService;

    @BizLog(name = "测验问题-分页条件查询", bizType = BizLogType.SELECT)
    @GetMapping(name = "分页条件查询", value = "/selectPageList")
    public Message<List<QuizTbQuestion>> selectPageList(@RequestQueryInfo QueryInfo queryInfo) {
        List<QuizTbQuestion> quizTbQuestionList = iQuizTbQuestionService.selectPageList(queryInfo);
        return Message.getInstance().setData(quizTbQuestionList).success("查询成功");
    }

    @GetMapping(name = "根据ID查询", value = "/selectById")
    public Message<QuizTbQuestion> selectById(@RequestParam Long id) {
        QuizTbQuestion resultEntity = iQuizTbQuestionService.selectById(id);
        return Message.getInstance().setData(resultEntity).success("查询成功");
    }

    @GetMapping(name = "获取问题详情", value = "/selectQuestionAndAnswersById")
    public Message<QuestionAnswersVo> selectQuestionAndOptionsById(@RequestParam Long id) {
        QuestionAnswersVo resultEntity = iQuizTbQuestionService.selectQuestionAndOptionsById(id);
        return Message.getInstance().setData(resultEntity).success("查询成功");
    }

    @GetMapping(name = "根据题库编码查询所有题目", value = "/selectBankInfoByBankCode")
    public Message<List<QuizTbQuestionListVo>> selectById(@RequestParam String bankCode) {
        List<QuizTbQuestionListVo> resultEntity = iQuizTbQuestionService.selectBankInfoByBankCode(bankCode);
        return Message.getInstance().setData(resultEntity).success("查询成功");
    }

    @BizLog(name = "测验问题-新增", bizType = BizLogType.INSERT)
    @PostMapping(name = "新增", value = "/save")
    public Message<Long> saveEntity(@RequestBody @Valid QuizTbQuestionAo entityAo) {
        iQuizTbQuestionService.insertService(entityAo);
        return Message.getInstance().setData(entityAo.getId()).success();
    }

    @BizLog(name = "测验问题-批量新增", bizType = BizLogType.INSERT)
    @PostMapping(name = "批量新增", value = "/saveList")
    public Message<List<Long>> saveEntityList(@RequestBody @Valid List<QuizTbQuestionAo> entityAos) {
        List<Long> ids = iQuizTbQuestionService.insertList(entityAos);
        return Message.getInstance().setData(ids).success();
    }

    @BizLog(name = "测验问题-更新", bizType = BizLogType.UPDATE)
    @PostMapping(name = "更新", value = "/update")
    public Message<Boolean> updateEntity(@RequestBody @Valid QuizTbQuestionAo entityAo) {
        iQuizTbQuestionService.updateService(entityAo);
        return Message.getInstance().success();
    }

    @BizLog(name = "测验问题-批量更新", bizType = BizLogType.UPDATE)
    @PostMapping(name = "批量更新", value = "/updateList")
    public Message<Integer> updateEntityList(@RequestBody @Valid List<QuizTbQuestionAo> entityAos) {
        Integer count = iQuizTbQuestionService.updateListBySelective(entityAos);
        return Message.getInstance().setData(count).success();
    }

    @BizLog(name = "测验问题-逻辑删除", bizType = BizLogType.DELETE)
    @PostMapping(name = "逻辑删除", value = "/logicDelete")
    public Message<Boolean> logicDelete(@RequestBody List<Long> ids) {
        iQuizTbQuestionService.logicDeleteByIds(ids);
        return Message.getInstance().success();
    }

    @BizLog(name = "测验问题-物理删除", bizType = BizLogType.DELETE)
    @PostMapping(name = "物理删除", value = "/delete")
    public Message<Boolean> delete(@RequestBody List<Long> ids) {
        iQuizTbQuestionService.deleteServiceByIds(ids);
        return Message.getInstance().success();
    }


}
